import { NoSkinCellRenderer } from "../../common/item/NoSkinCellRenderer";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { Language } from "../../../../../extend/language/Language";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { PetIslandUtil } from "../PetIslandUtil";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { SPlaceInfo } from "../../../../../Message/Game/SPlaceInfo";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { ColorConfig } from "../../../resource/ColorConfig";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { RemainTimeUtil } from "../../shopMall/RemainTimeUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { PetIslandStateData } from "../vo/PetIslandStateData";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GBitmap } from "../../../../../com/mui/controls/GBitmap";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class PetIslandPowerInfoItemRenderer
    
    export  class PetIslandPowerInfoItemRenderer extends NoSkinCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        /* internal  */onPositionHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandMapShowByPosition, this._vo.pos));
            return;
        }

        /* internal  */onGarrisonHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._garrisonBtn.label != Language.getString(28217)) 
            {
                if (this._garrisonBtn.label == Language.getString(28132)) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandGarrison, this._vo.placeId));
                }
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandGarrison, 0));
            }
            return;
        }

        /* internal  */onDiscardHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var onClickHandler: Function;

            var loc1;
            onClickHandler = null;
            e = arg1;
            onClickHandler = (arg1: int): void
            {
                if (arg1 == Alert.YES) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandDiscard, _vo.placeId));
                }
                return;
            }
            Alert.show(Language.getString(28205), null, Alert.YES | Alert.NO, null, onClickHandler);
            return;
        }

        /* internal  */onPetIslandMoveSucceedHandler(arg1: DataEvent): void
        {
            if (this._vo) 
            {
                this._garrisonBtn.label = PetIslandUtil.isInPlace(this._vo.pos) ? Language.getString(28217) : Language.getString(28132);
            }
            return;
        }

        /* internal  */onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this.contains(this._selectLine)) 
            {
                this.addChildAt(this._selectLine, 0);
            }
            return;
        }

        /* internal  */onMouseOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            DisplayUtil.removeMe(this._selectLine);
            return;
        }

        /* internal  */onResCompl(): void
        {
            ObjCreate.createGBitmap(ImagesConst.PetIslandPowerBaseIncomeText, 320, 12, this);
            this._selectBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.PetIslandPowerBaseItemSelectBg);
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            if (arg1) 
            {
                this.addChildAt(this._selectBg, 0);
            }
            else 
            {
                DisplayUtil.removeMe(this._selectBg);
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=null;
            if (typeof arg1 === "splaceinfo") 
            {
                this._vo = arg1 as SPlaceInfo;
                loc1 = HTMLUtil.addColor("·", ColorConfig.instance.getItemColorString(this._vo.pos.isLand + 2));
                this._name.htmlText = GameDefConfig.instance.getPetIslandName(this._vo.pos.isLand) + loc1 + GameDefConfig.instance.getPetIslandPlaceTypeName(this._vo.pos.placeType);
                this._position.htmlText = PetIslandUtil.getPosName(this._vo.pos);
                this._output.text = Language.getStringByParam(28127, this._vo.grassRemain + "/" + this._vo.grassTotal);
                this._speed.htmlText = Language.getStringByParam(28128, this._vo.exploitSpeed) + PetIslandUtil.getAdditionNum(this._vo.exploitSpeed);
                this._time.htmlText = Language.getStringByParam(28129, HTMLUtil.addColor(RemainTimeUtil.getRemainMinute(this._vo.occupySeconds, true, true, true, false, true), GlobalStyle.color1));
                this._income.text = this._vo.grassCount.toString();
                this._garrisonBtn.label = PetIslandUtil.isInPlace(this._vo.pos) ? Language.getString(28217) : Language.getString(28132);
                loc2 = PetIslandUtil.getState(new PetIslandStateData(this._vo.guildId, this._vo.isFighting, this._vo.protectSeconds));
            }
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._selectBg = ObjCreate.createGBitmap("", 0, 0, null);
            ObjCreate.createBg(0, 58, 550, 2, this, ImagesConst.SplitLine);
            this._state = ObjCreate.createGBitmap("", 3, 42, this);
            this._name = ObjCreate.createGTextField("", 0, 5, 145, 20, this, new GTextFormat(FontUtil.lishuName, 16, 16711935, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._name.mouseEnabled = false;
            this._position = ObjCreate.createGTextField("", 26, 32, 130, 20, this);
            this._position.addEventListener(flash.events.TextEvent.LINK, this.onPositionHandler);
            this._output = ObjCreate.createGTextField("", 150, 3, 160, 20, this);
            this._output.mouseEnabled = false;
            this._speed = ObjCreate.createGTextField("", 150, 20, 160, 20, this);
            this._speed.mouseEnabled = false;
            this._time = ObjCreate.createGTextField("", 150, 37, 130, 20, this, GlobalStyle._textFormat5);
            this._time.mouseEnabled = false;
            this._income = ObjCreate.createGTextField("", 320, 33, 80, 20, this, new GTextFormat(FontUtil.songtiName, 12, 11661311, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._income.mouseEnabled = false;
            this._garrisonBtn = ObjCreate.createGButton(Language.getString(28132), 430, 22, 42, 20, this);
            this._garrisonBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGarrisonHandler);
            var loc1=ObjCreate.createGButton(Language.getString(28133), 486, 22, 42, 20, this);
            loc1.addEventListener(flash.events.MouseEvent.CLICK, this.onDiscardHandler);
            Dispatcher.addEventListener(EventName.PetIslandMoveSucceed, this.onPetIslandMoveSucceedHandler);
            this._selectLine = new Object /* flash.display.Sprite */();
            this._selectLine.mouseEnabled = false;
            this._selectLine.graphics.lineStyle(2, 65407, 1);
            this._selectLine.graphics.drawRoundRect(1, 1, 554, 58, 6, 6);
            this._selectLine.graphics.endFill();
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOutHandler);
            LoaderHelp.addResCallBack(ResFileConst.PetIslandPowerBase, this.onResCompl);
            return;
        }

        /* internal */ /* var */_selectBg: GBitmap;

        /* internal */ /* var */_name: GTextFiled;

        /* internal */ /* var */_position: GTextFiled;

        /* internal */ /* var */_output: GTextFiled;

        /* internal */ /* var */_speed: GTextFiled;

        /* internal */ /* var */_time: GTextFiled;

        /* internal */ /* var */_state: GBitmap;

        /* internal */ /* var */_income: GTextFiled;

        /* internal */ /* var */_garrisonBtn: GButton;

        /* internal */ /* var */_selectLine: Object /* flash.display.Sprite */;

        /* internal */ /* var */_vo: SPlaceInfo;
    }
